//
//  WAMyTaskController.m
//  WalkiOS
//
//  Created by luqiuan on 2019/10/16.
//  Copyright © 2019 Chenmuzhou. All rights reserved.
//

#import "WAMyTaskController.h"
#import "WATaskListController.h"

@interface WAMyTaskController ()
@property (weak, nonatomic) IBOutlet UIView *bottomLineLB;
@property (weak, nonatomic) IBOutlet UIButton *taskBtn;
@property (weak, nonatomic) IBOutlet UIButton *myTaskBtn;
@property (weak, nonatomic) IBOutlet UIButton *historyBtn;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *bottomLineLeftCons;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *scrollViewWidthCons;
@property (weak, nonatomic) IBOutlet UIScrollView *scrollView;


@property (strong, nonatomic) WATaskListController *taskListVC;
@property (strong, nonatomic) WATaskListController *myTaskListVC;
@property (strong, nonatomic) WATaskListController *historyTaskListVC;
@end

@implementation WAMyTaskController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.scrollViewWidthCons.constant = WNScreenWidth * 3;
    
    self.taskListVC = [[WATaskListController alloc] initWtihType:0];
    [self.scrollView addSubview:self.taskListVC.view];
    [self addChildViewController:self.taskListVC];
    self.taskListVC.view.backgroundColor = ThemeColor;
    [self.taskListVC.view mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.bottom.left.equalTo(self.scrollView);
        make.width.mas_equalTo(WNScreenWidth);
    }];
    
    self.historyTaskListVC = [[WATaskListController alloc] initWtihType:2];
    [self.scrollView addSubview:self.historyTaskListVC.view];
    [self addChildViewController:self.historyTaskListVC];
    self.historyTaskListVC.view.backgroundColor = ThemeColor;
    [self.historyTaskListVC.view mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.bottom.right.equalTo(self.scrollView);
        make.width.mas_equalTo(WNScreenWidth);
    }];
    
    self.myTaskListVC = [[WATaskListController alloc] initWtihType:1];
    [self.scrollView addSubview:self.myTaskListVC.view];
    self.myTaskListVC.view.backgroundColor = ThemeColor;
    [self.myTaskListVC.view mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.bottom.equalTo(self.scrollView);
        make.left.equalTo(self.taskListVC.view.mas_right);
        make.width.mas_equalTo(WNScreenWidth);
    }];
}
- (IBAction)backAction:(id)sender {
    [self.navigationController popViewControllerAnimated:YES];
}

- (IBAction)taskBtnAction:(id)sender {
    if (self.taskBtn.selected) {
        return;
    }
    self.taskBtn.selected = YES;
    self.myTaskBtn.selected = NO;
    self.historyBtn.selected = NO;
    [self.scrollView setContentOffset:CGPointMake(0, 0) animated:YES];
}

- (IBAction)myTaskBtnAction:(id)sender {
    if (self.myTaskBtn.selected) {
        return;
    }
    self.taskBtn.selected = NO;
    self.myTaskBtn.selected = YES;
    self.historyBtn.selected = NO;
    [self.scrollView setContentOffset:CGPointMake(WNScreenWidth, 0) animated:YES];
}

- (IBAction)historyTaskBtnAction:(id)sender {
    if (self.historyBtn.selected) {
        return;
    }
    self.taskBtn.selected = NO;
    self.myTaskBtn.selected = NO;
    self.historyBtn.selected = YES;
    [self.scrollView setContentOffset:CGPointMake(WNScreenWidth * 2, 0) animated:YES];
}

- (void)scrollViewDidScroll:(UIScrollView *)scrollView{
    CGFloat offset_X = scrollView.contentOffset.x;
    self.bottomLineLeftCons.constant = offset_X/3.f;
    [self.view layoutIfNeeded];
}

- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView{
    self.taskBtn.selected = NO;
    self.myTaskBtn.selected = NO;
    self.historyBtn.selected = NO;
    if (scrollView.contentOffset.x == 0) {
        self.taskBtn.selected = YES;
    }else if (scrollView.contentOffset.x == WNScreenWidth * 2) {
        self.historyBtn.selected = YES;
    }else{
        self.myTaskBtn.selected = YES;
    }
}
@end
